import { reqLogin } from "../../api/user";

const state = {
  token: "",
};

const actions = {
  async login({ commit }, user) {
    const { username, password } = user;
    const res = await reqLogin(username, password);
    if (res.data.code === 20000) {
      console.log(res.data);
      commit("LOGIN", res.data.data.token);
    } else {
      console.log(res.data.message);
    }
  },
};
const mutations = {
  LOGIN(state, token) {
    state.token = token;
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
};
